package com.wanmait.deliverymangementsystem.runnercontroller;

import com.github.pagehelper.PageInfo;
import com.wanmait.deliverymangementsystem.pojo.Runner;
import com.wanmait.deliverymangementsystem.pojo.Tasks;
import com.wanmait.deliverymangementsystem.service.RunnerService;
import com.wanmait.deliverymangementsystem.service.TaskService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("runner")
public class RunnerIndexController {

    @Resource
    private RunnerService runnerService;
    @Resource
    private TaskService taskService;
    @RequestMapping("index")
    @ModelAttribute("tasksPageInfo")
    public PageInfo<Tasks> index(HttpSession session){
      Runner runner=(Runner)session.getAttribute("runner");
    PageInfo<Tasks> tasksPageInfo=  taskService.runnerFindMyOrders(0,runner.getId());
    return tasksPageInfo;
    }
    @RequestMapping("logOut")
    public String logOut(HttpSession session){
        Runner runner =(Runner) session.getAttribute("runner");
        runnerService.taskAvailable(false,runner.getId());
        session.invalidate();
        return "redirect:/runner/login";
    }

}
